//
//  ObjectStore
//
//  Created by Caue W. on 2011-02-22.
//  Copyright (c) 2011 __MyCompanyName__. All rights reserved.
//
package time.runtime;
import time.types.ds.Future;
import time.types.ds.ObjectHash;
import time.types.ds.Key;

interface ObjectStore
{
	/**
	*  Sets the depth of activated objects
	**/
	var activationDepth(get_activationDepth, set_activationDepth):Int;
	
	/**
	*  Async operations. Warning - not fully supported by all platforms
	**/
	var async(get_async, never):AsyncObjectStore;
	
	
	function insert<T>(obj : T, errorIfExists : Bool = false) : Key<T>;
	function insertAll<T>(objs : Iterable<T>, errorIfExists : Bool = false) : ObjectHash<T, Key<T>>;
	
	function update<T>(obj : T) : Void;
	function updateAll<T>(objs : Iterable<T>) : Void;
	
	function sync(obj : Dynamic) : Void;
	function syncAll(objs : Iterable<Dynamic>) : Void;
	
	function delete<T>(obj : T) : Bool;
	
	function get<T>(key : Key<T>) : T;
	function getWith<T>(c : Class<T>, key : String) : T;
	
	function cleanup() : Void;
	function close() : Void;
	function open() : Void;
	function isOpen() : Bool;
	
	function dispose(obj : Dynamic) : Bool;
}

interface AsyncObjectStore
{
	
	function insertAsync<T>(obj : T, errorIfExists : Bool = false) : Future<Key<T>>;
	function insertAllAsync<T>(objs : Iterable<T>, errorIfExists : Bool = false) : Future<ObjectHash<T, Key<T>>>;
	
	function updateAsync<T>(obj : T) : Future<Void>;
	function updateAllAsync<T>(objs : Iterable<T>) : Future<Void>;
	
	function deleteAsync<T>(obj : T) : Future<Bool>;
	
	function getAsync<T>(key : Key<T>) : Future<T>;
	function getWithAsync<T>(c : Class<T>, key : String) : Future<T>;
	
	
	function closeAsync() : Future<Void>;
	function openAsync() : Future<Void>;
	function isOpen() : Bool;
	
	//sync functions (because they don't involve 
	function cleanup() : Void;
	function dispose(obj : Dynamic) : Bool;
}